import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

// 从本地存储中获取初始状态
const initialState = {
  uploadData: uni.getStorageSync("uploadData") || {},
  qimenResponseData: uni.getStorageSync("qimenResponseData") || {},
  startAIData: uni.getStorageSync("startAIData") || {
    bashen: "",
    tianpan: "",
    dipan: "",
    baxing: "",
    bamen: "",
  },
  xunJu: {},
  AIContentData: [],
};

export default new Vuex.Store({
  state: initialState,
  mutations: {
    // 奇门返回的数据
    setQimenResponseData(state, data) {
      state.qimenResponseData = data;
      uni.setStorageSync("qimenResponseData", data);
    },
    // 奇门排盘数据
    setUploadData(state, newData) {
      state.uploadData = {
        ...state.uploadData,
        ...newData,
      };
      uni.setStorageSync("uploadData", state.uploadData);
    },
    setStartAIData(state, newData) {
      state.startAIData = {
        ...state.startAIData,
        ...newData,
      };
      // console.log(50, state.startAIData);
      uni.setStorageSync("startAIData", state.startAIData);
    },
    setXunJu(state, data) {
      state.xunJu = data;
      uni.setStorageSync("xunJu", data);
    },
    setAIContentData(state, data) {
      state.AIContentData = data;
      console.log(51, state.AIContentData);
      uni.setStorageSync("AIContentData", data);
    },
  },
});
